package com.idbk.chargestation.activity.user;


import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.idbk.chargestation.R;
import com.idbk.chargestation.adapter.BookingTabAdapter;
import com.idbk.chargestation.base.BaseActivity;

/**
 * 我的预约
 * @author zhx
 *
 */
public class ActivityMyBooking extends BaseActivity implements OnClickListener {

	private final static String TAG = ActivityMyBooking.class.getSimpleName();

	private ViewPager mPager;
	private RadioGroup mRadioGroup;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);		

		setContentView(R.layout.activity_my_booking);

		setupView();
	}

	private void setupView() {
		setupToolBar2();//显示标题栏

		mRadioGroup = (RadioGroup)findViewById(R.id.radiogroup_tab);
		RadioButton mRadioButtonLeft= (RadioButton)findViewById(R.id.tab_item_left);
		RadioButton mRadioButtonRight= (RadioButton)findViewById(R.id.tab_item_right);
		if (mRadioButtonLeft != null && mRadioButtonRight != null) {
			mRadioButtonLeft.setOnClickListener(this);
			mRadioButtonRight.setOnClickListener(this);
		}
		String[] mTabTitles = getResources().getStringArray(R.array.booking_main_tab);

		mPager = (ViewPager)findViewById(R.id.viewpager);
		BookingTabAdapter adapter = new BookingTabAdapter(getSupportFragmentManager(),mTabTitles);
		mPager.setAdapter(adapter);
		//
		mPager.setOffscreenPageLimit(2);

		mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

			@Override
			public void onPageSelected(int arg0) {
				// TODO Auto-generated method stub
				if(arg0 == 0) {
					mRadioGroup.check(R.id.tab_item_left);
					Log.e(TAG, "0");
				} else if(arg0 == 1) {
					mRadioGroup.check(R.id.tab_item_right);
				} 
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
			}
		});

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId() == R.id.tab_item_left) {
			mPager.setCurrentItem(0, true);
		} else if(v.getId() == R.id.tab_item_right) {
			mPager.setCurrentItem(1, true);
		}
	}

}

